import { createStore } from "vuex";
import moment from "moment-timezone";

// 创建一个新的 store 实例
const store = createStore({
  state() {
    return {
      timeZones: moment.tz.names(),
      CurrentZones: "Asia/Chongqing",
      timeIns: moment().tz("Asia/Chongqing"),
    };
  },
  getters: {
    CurrentTotalTime: (state) => {
      return state.timeIns.format();
    },
    CurrentHours: (state) => {
      const currentHour = state.timeIns.toArray()[3];
      const currentMinute = state.timeIns.toArray()[4];
      return ((currentHour % 12) + currentMinute / 60) * (360 / 12);
    },
    CurrentMinutes: (state) => {
      const currentMinute = state.timeIns.toArray()[4];
      const currentSecond = state.timeIns.toArray()[5];
      return (currentMinute + currentSecond / 60) * (360 / 60);
    },
    CurrentSeconds: (state) => {
      const currentSecond = state.timeIns.toArray()[5];
      return currentSecond * (360 / 60);
    },
  },
  mutations: {
    UpDateNewTime(state) {
      state.timeIns = moment().tz(state.CurrentZones);
    },
    changeZones(state, payload) {
      state.CurrentZones = payload;
    },
  },
});

export default store;
